trigger trg_OpportunityLineItem on OpportunityLineItem (before insert, after delete) 
{
    
    Map<ID,ID> OpportunityIdMap = new Map<ID,ID>();
    Map<ID,ID> OpportunityIdInsertionMap = new Map<ID,ID>();
     
    if(Trigger.isInsert)
    {
        /*integer counter = 1; 
        for(OpportunityLineItem oppItemObject : Trigger.New)
        {
            //Using the Total Opportunity Item Count Values...
            oppItemObject.Item_Number__c = oppItemObject.Total_Number_of_Opportunity_Item__c + counter;
            //Adding in the counter for the batch Inserting operation...
            counter++;
            
            System.debug('The Opportunity Line Item Number in Trigger => '+oppItemObject.Item_Number__c );
            
    	}*/
    	
    	for(OpportunityLineItem oppItemObject : Trigger.New)
        {
        	OpportunityIdInsertionMap.put(oppItemObject.OpportunityId,oppItemObject.OpportunityId);
        }
        
        
        if(OpportunityIdInsertionMap.size() > 0)
        {
        	for(ID opportunityID : OpportunityIdInsertionMap.keyset())
        	{
        		integer counter = 1;
        		
        		for(OpportunityLineItem oppItemObject : Trigger.New)
        		{
        			if(oppItemObject.OpportunityId == opportunityID)
        			{
        				//Using the Total Opportunity Item Count Values...
			            oppItemObject.Item_Number__c = oppItemObject.Total_Number_of_Opportunity_Item__c + counter;
			            //Adding in the counter for the batch Inserting operation...
			            counter++;
			            
			            System.debug('The Opportunity Line Item Number in Trigger => '+oppItemObject.Item_Number__c );
        			}
        			
        		}
        		
        	}
        	
        }
    	   
    
    }
    
    
    
    
    
    if(Trigger.isDelete)
    {
        
        for(OpportunityLineItem oppItemObject : Trigger.old)
        {
            
            OpportunityIdMap.put(oppItemObject.Id,oppItemObject.OpportunityId);
            
        }
        
    }
    
    if(OpportunityIdMap.size() > 0)
    {
        
        //List<Opportunity> OpportunityList = new List<Opportunity>([Select Id, (Select Item_Number__c From OpportunityLineItems) From Opportunity where Id IN : OpportunityIdMap.values() ]);
        //Creating the Updating List...
        List<OpportunityLineItem> oppItemUpdateList = new List<OpportunityLineItem>();
        
        for(Opportunity OpportunityObject : [Select Id, (Select Id,Item_Number__c From OpportunityLineItems ORDER BY Item_Number__c ASC) From Opportunity where Id IN : OpportunityIdMap.values() ])
        {
            integer counter = 1;
            for(OpportunityLineItem oppItem  : OpportunityObject.OpportunityLineItems)
            {
                oppItem.Item_Number__c = counter;
                
                //Adding the counter...
                counter ++;
                
                //Now Adding in the list...
                oppItemUpdateList.add(oppItem );
                
            }
        }
        
        //Now Update the Opportunity Line Item...
        if(oppItemUpdateList.size() > 0)
            update oppItemUpdateList;
            
        
    }
    
}